<template>
    <div class="user">
        <commonUserinfo :userInfoData="{userItemIndex:itemIndex,userLeftHeight:userLeftHeight,$parent:$parent}">
            <div id="applyInfo" class="user_main_right f_left text_center" ref="userRightH">
                <div class="applyInfo_search" v-if="showApplyInfo">
                    <table width="100%" class="ticketTable">
                        <thead>
                            <tr>
                                <td width="70px">真实姓名</td>
                                <td>报考专业</td>
                                <td>订单编号</td>
                                <td>报名方式</td>
                                <td>网络学习</td>
                                <td width="220px">操作</td>
                            </tr>
                        </thead>
                        <tbody>
                            <!-- 继续教育 -->
                            <tr v-for="item in education" :key="item.id">
                                <td>{{item.realName}}</td>
                                <td>{{item.majorName}}</td>
                                <td>{{item.tradeNo}}</td>
                                <td v-if="item.applyWay==0">个人报名</td>
                                <td v-if="item.applyWay==1">企业报名</td>
                                <td>
                                    <template v-if="item.tradeStatus!=2&&item.applyWay==0">
                                        <router-link type="button" class="apply_info_btn" title="继续报名"
                                            :to="String.Format('/home/apply/zhifubaopre/{0}',item.tradeNo)">继续报名
                                        </router-link>
                                    </template>
                                    <template v-if="item.tradeStatus==2">
                                        <template v-if="item.isFinish==0">
                                            <router-link type="button" class="apply_info_btn" :to="String.Format('/home/play/task/1/{0}/{1}/{2}',
                                    		item.tradeNo,item.period,item.id)" title="去学习">去学习</router-link>
                                        </template>
                                        <template v-if="item.isFinish==1">
                                            <a class="apply_info_btn" target="_blank" title="查看证书"
                                                @click="lookCertificate(item.id)">查看证书</a>
                                        </template>
                                    </template>
                                </td>
                                <td>
                                    <template v-if="item.tradeStatus!=2&&item.applyWay==0">
                                        <a type="button" class="apply_info_btn apply_delete" title="删除"
                                            @click="deleteApply(item.tradeNo)">删除</a>
                                    </template>
                                    <template v-if="item.tradeStatus==2">
                                        <template v-if="item.applyWay==0">
                                            <a v-if="item.applyPrice>0" class="apply_info_btn" target="_blank"
                                                title="查看发票" @click="lookInvoice(item.tradeNo)">查看发票</a>
                                            <a class="apply_info_btn apply_delete" title="申请退费" target="_blank"
                                                @click="refundBtn(item)">申请退费</a>
                                        </template>
                                    </template>
                                </td>
                            </tr>
                            <!-- 三类人员-->
                            <tr v-for="item in slry" :key="item.id">
                                <td>{{item.realName}}</td>
                                <td>{{item.majorName}}</td>
                                <td>{{item.tradeNo}}</td>
                                <td v-if="item.applyWay==0">个人报名</td>
                                <td v-if="item.applyWay==1">企业报名</td>
                                <td>
                                    <template v-if="item.tradeStatus!=2&&item.applyWay==0">
                                        <router-link title="继续报名" type="button" class="apply_info_btn"
                                            :to="String.Format('/home/apply/zhifubaopre/{0}',item.tradeNo)">继续报名
                                        </router-link>
                                    </template>
                                    <template v-if="item.tradeStatus==2">
                                        <template v-if="item.isFinish==0&&item.isResit!=1">
                                            <router-link title="去学习" type="button" class="apply_info_btn" :to="String.Format('/home/play/trainTask/0/{0}/0/{1}',
                                            item.tradeNo,item.id)">去学习</router-link>
                                        </template>
                                    </template>
                                </td>
                                <td>
                                    <template v-if="item.tradeStatus!=2&&item.applyWay==0">
                                        <a type="button" title="删除" class="apply_info_btn apply_delete"
                                            @click="deleteApply(item.tradeNo)">删除</a>
                                    </template>
                                    <template v-if="item.tradeStatus==2">
                                        <!-- <a class="apply_info_btn" title="查看准考证" @click="getMyAdmissionSlryTicket(item.tradeNo)">查看准考证</a> -->
                                        <template v-if="item.applyWay==0">
                                            <template v-if="item.isResit!=1">
                                                <a v-if="item.applyPrice>0" class="apply_info_btn" target="_blank"
                                                    title="查看发票" @click="lookInvoice(item.tradeNo)">查看发票</a>
                                                <a class="apply_info_btn apply_delete" target="_blank" title="申请退费"
                                                    @click="refundBtn(item)">申请退费</a>
                                            </template>
                                            <template v-else>
                                                <a v-if="item.applyPrice>0" class="apply_info_btn" target="_blank"
                                                    title="查看发票" @click="lookInvoice(item.tradeNo)">查看发票</a>
                                            </template>
                                        </template>
                                    </template>
                                </td>
                            </tr>
                            <!-- 特种工 -->
                            <tr v-for="item in tzg" :key="item.id">
                                <td>{{item.realName}}</td>
                                <td>{{item.majorName}}</td>
                                <td>{{item.tradeNo}}</td>
                                <td v-if="item.applyWay==0">个人报名</td>
                                <td v-if="item.applyWay==1">企业报名</td>
                                <td>
                                    <template v-if="item.tradeStatus!=2&&item.applyWay==0">
                                        <!-- <template v-if="item.checkStatus==1"> -->
                                        <router-link title="继续报名" type="button" class="apply_info_btn"
                                            :to="String.Format('/home/apply/zhifubaopre/{0}',item.tradeNo)">继续报名
                                        </router-link>
                                        <!-- </template> -->
                                    </template>
                                    <template v-if="item.tradeStatus==2">
                                        <template
                                            v-if="item.practicalIsFinish==0&&item.isResit!=1||item.theoryIsFinish==0&&item.isResit!=1">
                                            <router-link title="去学习" type="button" class="apply_info_btn" :to="String.Format('/home/play/trainTask/0/{0}/0/{1}',
                                    		item.tradeNo,item.id)">去学习</router-link>
                                        </template>
                                    </template>
                                    <!-- <template v-if="item.applyWay==0">
                                        <a class="apply_info_btn" title="查看报名表" @click="lookApplyTable(item.tradeNo)">查看报名表</a>
                                    </template> -->
                                </td>
                                <td>
                                    <template v-if="item.tradeStatus!=2&&item.applyWay==0">
                                        <a type="button" title="删除" class="apply_info_btn apply_delete"
                                            @click="deleteApply(item.tradeNo)">删除</a>
                                    </template>
                                    <template v-if="item.tradeStatus==2">
                                        <!-- <a class="apply_info_btn" title="查看理论准考证" @click="getMyAdmissionTheoryTicket(item.tradeNo)">查看理论准考证</a>
                                        <a class="apply_info_btn" title="查看实操准考证" @click="getMyAdmissionPracticalTicket(item.tradeNo)">查看实操准考证</a> -->
                                        <template v-if="item.applyWay==0">

                                            <template v-if="item.isResit!=1">
                                                <a v-if="item.applyPrice>0" class="apply_info_btn" target="_blank"
                                                    title="查看发票" @click="lookInvoice(item.tradeNo)">查看发票</a>
                                                <a class="apply_info_btn apply_delete" target="_blank" title="申请退费"
                                                    @click="refundBtn(item)">申请退费</a>
                                            </template>
                                            <template v-else>
                                                <a v-if="item.applyPrice>0" class="apply_info_btn" target="_blank"
                                                    title="查看发票" @click="lookInvoice(item.tradeNo)">查看发票</a>
                                            </template>

                                            <!-- <a v-if="item.applyPrice>0" class="apply_info_btn" target="_blank" title="查看发票"
                                                @click="lookInvoice(item.tradeNo)">查看发票</a>
                                            <a class="apply_info_btn apply_delete" title="申请退费" target="_blank" @click="refundBtn(item)">申请退费</a>
                                       -->
                                        </template>
                                    </template>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <!-- 没有报名信息-->
                <div class="user_userInfo apply_info apply_info_no_list color666" v-if="!showApplyInfo">
                    <h3>报名信息</h3>
                    <div class="apply_info_item">
                        <img src="/static/img/user/noimformation_02.png">
                        <p>抱歉您当前没有报名信息~<br>您可以点击 <router-link to="/home">立即报名</router-link>前往报名~</p>
                    </div>
                </div>
            </div>
        </commonUserinfo>
        <!-- 退款 -->
        <el-dialog class="refund_dialog text_center dialog" title="提示" :visible.sync="dialogVisibleRefund" width="40%">
            <div class="refund_dialog_content">
                <!-- <img src="/static/img/wenxintishi.png" width="400px" height="72px"> -->
                <el-form label-width="100px" class="text_left"
                    style="width: 400px;margin: 60px auto;margin-bottom: 100px;">
                    <el-form-item label="订单编号：">
                        <p>{{refundData.tradeNo}}</p>
                    </el-form-item>
                    <el-form-item label="退费原因：">
                        <el-input type="textarea" cols="10" onkeyup="this.value=this.value.substring(0, 200)"
                            placeholder="最多可输入200字!" v-model="refundForm.reason"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisibleRefund = false">取 消</el-button>
                <el-button type="primary" @click="refundConfirm">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import commonUserinfo from '../../../components/cont_education/c_userinfo.vue'
    export default {
        name: "apply_info",
        data: function() {
            return {
                dialogVisibleRefund: false,
                refundForm: {
                    reason: ''
                },
                refundData: {},
                itemIndex: 1,
                userLeftHeight: '',
                showApplyInfo: true,
                slry: [], //三类人员
                tzg: [], //特种工
                education: [], //继续教育
                slryTzg: [], //三类人员特种工
                projectId: 0,
            }
        },
        mounted: function() {
            this.getApplyInfo();
        },
        methods: {
            getApplyInfo: function() {
                var that = this;
                this.showApplyInfo = false;
                this.common.post(this.api.getApplyInfo, {
                    projectId: this.projectId
                }, function(res) {
                    that.education = res.resultMap.education;
                    that.slry = res.resultMap.slry;
                    that.tzg = res.resultMap.tzg;
                    setTimeout(function() {
                        that.userLeftHeight = that.$refs.userRightH.offsetHeight - 2 + "px";
                    }, 10);
                    if (that.education.length > 0 || that.slry.length > 0 || that.tzg.length > 0) {
                        that.showApplyInfo = true;
                    } else {
                        that.showApplyInfo = false;
                    }
                });
            },
            deleteApply: function(tradeNo) {
                var that = this;
                this.common.post(this.api.delApply, {
                    tradeNo: tradeNo
                }, function(res) {
                    that.$message.success('删除成功！');
                    setTimeout(function() {
                        window.location.reload();
                    }, 1000);
                }, function(error) {
                    that.$message.error(error.resultMsg);
                });
            },
            lookInvoice: function(tradeNo) {
                this.common.toPage("/cont_education/other/invoice/" + tradeNo);
            },
            lookCertificate: function(applyid) {
                var that = this;
                this.common.post(this.api.lookCertificate, {
                    applyid: applyid
                }, function(res) {
                    if (res.resultMap == null) return;
                    that.$message.success("正在生成中...");
                    setTimeout(function() {
                        window.open(res.resultMap);
                    }, 2000);
                });
            },
            // lookApplyTable: function(tradeNo) {
            //     var that = this;
            //     this.common.post(this.api.getPersonApplyForm, {
            //         tradeNo: tradeNo
            //     }, function(res) {
            //         if (!String.isEmptyOrNUll(res.resultMap)) {
            //             setTimeout(function() {
            //                 window.open(res.resultMap);
            //             }, 2000);
            //         } else {
            //             that.$message.error("当前暂无报名表！");
            //         }
            //     });
            // },
            refundBtn: function(data) {
                this.dialogVisibleRefund = true;
                this.refundData = data;
                this.refundForm.reason = "";
            },
            refundConfirm: function() {
                if (this.refundForm.reason == '') {
                    this.$message.error('请输入退款原因！')
                    return;
                }
                var that = this;
                this.common.post(this.api.applyForRefund, {
                    tradeNo: this.refundData.tradeNo,
                    reason: this.refundForm.reason
                }, function(res) {
                    that.$message.success(res.resultMap);
                    that.dialogVisibleRefund = false;
                });
            },
            // getMyAdmissionTheoryTicket: function(tradeNo) {
            //     var that = this;
            //     this.common.post(this.api.getMyAdmissionTheoryTicket, {
            //         tradeNo: tradeNo
            //     }, function(res) {
            //         if (String.isEmptyOrNUll(res.resultMap)) {
            //             that.$message.error('准考证尚未制作，请稍后！');
            //             return;
            //         }
            //         that.$message.success('正在生成中...');
            //         setTimeout(function() {
            //             window.open(res.resultMap);
            //         }, 2000);
            //     });
            // },
            // getMyAdmissionPracticalTicket: function(tradeNo) {
            //     var that = this;
            //     this.common.post(this.api.getMyAdmissionPracticalTicket, {
            //         tradeNo: tradeNo
            //     }, function(res) {
            //         if (String.isEmptyOrNUll(res.resultMap)) {
            //             that.$message.error('准考证尚未制作，请稍后！');
            //             return;
            //         }
            //         that.$message.success('正在生成中...');
            //         setTimeout(function() {
            //             window.open(res.resultMap);
            //         }, 2000);
            //     });
            // },
            // getMyAdmissionSlryTicket: function(tradeNo) {
            //     var that = this;
            //     this.common.post(this.api.getMyAdmissionSlryTicket, {
            //         tradeNo: tradeNo
            //     }, function(res) {
            //         if (String.isEmptyOrNUll(res.resultMap)) {
            //             that.$message.error('准考证尚未制作，请稍后！');
            //             return;
            //         }
            //         that.$message.success('正在生成中...');
            //         setTimeout(function() {
            //             window.open(res.resultMap);
            //         }, 2000);
            //     }, function(error) {
            //         that.$message.error('准考证尚未制作，请稍后！');
            //     });
            // },
            // toSlryResit: function() {
            //     this.common.post(this.api.slryapplyById, {}, function(res) {
            //         window.location.reload();
            //     });
            // }
        },
        components: {
            commonUserinfo
        }
    }
</script>

<style>
    .search_info form.el-form {
        width: 100%;
        text-align: left;
        margin-top: 20px;
        margin: 30px;
    }

    .user_apply_form_item {
        width: 300px;
        float: left;
        display: inline-block;
    }

    .user_apply_form_item_search {
        display: inline-block;
        background: #3a89cc;
        color: #fff;
        border: none;
        outline: none;
        font-size: 16px;
        display: inline-block;
        width: 80px;
        height: 32px;
        line-height: 32px;
        border-radius: 4px;
        margin: 0 10px;
        margin-left: 30px;
    }

    .applyInfo_search .apply_info_btn {
        width: 88px !important;
        /* padding: 0 5px !important; */
        margin: 2px 5px;
        height: 34px;
        line-height: 34px;
        font-size: 14px;
        display: inline-block;
        overflow: hidden;
    }

    .applyInfo_search .ticketTable tr td {
        padding: 0;
    }
</style>
